package modelLayer;
import java.io.Serializable;
import java.util.ArrayList;

/**
 * Singleton container for Owner objects
 * 
 * @author Nick Pedersen
 * @version 0.1
 */
public class OwnerContainer implements Serializable{
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<Owner> owners;
    private static OwnerContainer instance;

    /**
     * Constructor for objects of class OwnerContainer
     */
    private OwnerContainer(){
        owners = new ArrayList<Owner>();
    }

    /**
     * getInstance - Returns the instance of this container
     * @Return OwnerContainer - Returns the instance of this container
     */
    public static OwnerContainer getInstance(){
       if(instance == null){
           instance = new OwnerContainer();
       }
       
       return instance;
    }
    
    /**
     * addOwner - Adds a Owner object to the container
     * @Param Owner - The Owner object to be added
     */
    public void addOwner(Owner o){
        owners.add(o);
    }
    
    /**
     * findOwner - Finds and return an Owner object
     * @Param String name - The name of the owner object
     * @Return Owner - The owner object found
     */
    public Owner findOwner(String name){
        Owner o = null;
        for(Owner owner : owners){
            if(owner.getName().toLowerCase().equals(name.toLowerCase())){
                o = owner;
            }
        }
        return o;
    }
    
    /**
     * getContainer - Returns an ArrayList of Owners
     * @Return ArrayList<Owner> - Returns the ArrayList of Owners
     */
    public ArrayList<Owner> getContainer(){
        return owners;
    }

	public void remove(Owner o) {
		owners.remove(o);
	}
}
